package application.model
{
	import application.ApplicationFacade;
	import com.actionscriptnotes.external.Configuration;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	
	import mx.controls.Alert;
	
	import org.puremvc.interfaces.IProxy;
	import org.puremvc.patterns.proxy.Proxy;
	
	/**
	 * Handles xml configuration loading.
	 * Adds values to Proxy data object.
	 */	
	public class ConfigProxy extends Proxy implements IProxy
	{
		public static const NAME:String = "ConfigProxy";
		
		private var config:Configuration;
		
		public function ConfigProxy(swfPath:String)
		{
			super( NAME, new Object );
			
			config = Configuration.getInstance();
			config.addEventListener( Configuration.INIT, onConfigInit );
			config.addEventListener( Configuration.ERROR, onConfigError );
			config.loadConfiguration( swfPath + "/config.xml" );
		}
		
		private function onConfigInit(event:Event):void
		{
			this.data = config;
			sendNotification( ApplicationFacade.CONFIG_INIT );
		}
		
		private function onConfigError(event:IOErrorEvent):void
		{
			Alert.show( event.text, "Error" );
		}
	}
}